var currentPage=1;
var sortTypeId="";
var propertyTypeId="";
var allSort="";
var addTimeSort="";
var gPriceSort="";
var dPriceSort="";
var collectNumSort="";
var saleNumSort="";
var fenleiId="";
var shuxinId="";
var priceId=1;
var shangquanid="";
var dianpuleixing="";
var	remaigoodss="";
var	shifoubaohuans="";
var	jingbidikous="";
var qujianshu="";
var qipijianshu="";
//jinbizhongxin("","","","","","","","","");
//分类
function fenlei(){
	$("#sortUl").html("");
     $.ajax({
			url: urlcore + "/api/sortType/Primaryclassification?coder=2",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				 var suns=0;
				 var sortUl="";
           	$.each(data.data.sortTypeList,function(i,n){
           		suns++;
           		 if(suns==1){
sortUl+='<li><a href="javascript:TwoclassificationFenlei2();">全部分类</a></li>'; 
				  }
 sortUl+='<li><a href="javascript:TwoclassificationFenlei('+n.id+');">'+n.sortName+'</a></li>'; 
           	});
           	$("#sortUl").append(sortUl);
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}
function TwoclassificationFenlei2(){
	$("#area span").text("全部分类");
	fenleiId="";
	 $('#qiugou').html("");
	 currentPage=1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}


function TwoclassificationFenlei(str){
	 	$("#sortSon").html("");
	    $.ajax({
			url: urlcore + "/api/sortType/TwoGoodsAlls?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	
           	$.each(data.data,function(g,h){
    var Fenleierji='<li id="'+h.id+'"><a href="javascript:selectChanPinByfenlei('+h.id+',\''+h.sortName+'\');">'+h.sortName+'</a></li>';
           			$("#sortSon").append(Fenleierji);
           	});
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}


///------------------------------------分类



function shuxin(){
	$("#fengge").html("");
     $.ajax({
			url: urlcore + "/api/sortType/Primaryclassification?coder=1",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	 var fengge="";
           	var conut=0;
           	$.each(data.data.propertyTypeList,function(g,h){
           		conut++;
           		if(conut==1){
               fengge+='<li class="w_on1"><a href="javascript:TwoclassificationShuxin2();">全部属性</a></li>';
           		}
           	   fengge+='<li><a href="javascript:TwoclassificationShuxin('+h.id+');">'+h.propertyName+'</a></li>';

           	});
           		$("#fengge").append(fengge);
			}, 
			error:function() {
				/* Act on the event*/ 
				alert("error");
			}
		});
}

function  TwoclassificationShuxin2(){
	$("#wage span").text("全部属性");
	shuxinId="";
		currentPage=1;
	$("#chanping").html("");
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

function TwoclassificationShuxin(str){
	 	$("#erji").html("");
	    $.ajax({
			url: urlcore + "/api/sortType/Twoclassification?id="+str,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
           	var conut=0;
           	var erji="";
           	$.each(data.data,function(g,h){
           		conut++;
           		if(conut==1){
           		 erji='<li class="shu_curr" id="'+h.id+'"><a href="javascript:selectChanPinByShuxin('+h.id+',\''+h.propertyName+'\');">'+h.propertyName+'</a></li>';
           		}else{
           		erji+='<li id="'+h.id+'"><a href="javascript:selectChanPinByShuxin('+h.id+',\''+h.propertyName+'\');">'+h.propertyName+'</a></li>';
           			
           		}
           	});
           	   erji+='<li id="">其他</li>';
           	$("#erji").append(erji);
			}, 
			error:function() {
				/* Act on the event*/    //商品类别已完结
				alert("error");
			}
		});
}

function selectChanPinByfenlei(id,name){
	$("#area span").text(name);
	fenleiId=id;
	currentPage=1;
	  $("#chanping").html("");
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
function  selectChanPinByShuxin(id,name){
	$("#wage span").text(name);
	shuxinId=id;
	currentPage=1;
	  $("#chanping").html("");
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
function selectChanPinByprice(id,name){
	$("#price span").text(name);
	priceId=id;
	currentPage=1;
	  $("#chanping").html("");
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}
//根据条件查询热卖信息
var ss=0;
selectRemai();
function selectRemai(){
		if(currentPage==1 || currentPage==2 || ss!=0){
	       	$.ajax({ 
	       	url:urlcore+"/api/goods/selectGoodsListByCondition?current="+currentPage+"&goodsType="+remaigoodss+"&goldRate=0&isReturnedOfSevenDays="+shifoubaohuans+"&sortTypeId="+fenleiId+"&propertyTypeId="+shuxinId+"&sort="+priceId+"&sellerType="+dianpuleixing+"&betweenMoney="+qujianshu+"&tradeAreaId="+shangquanid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					ss=data.data.list.length;
					//alert(JSON.stringify(data.data.list));
					  $.each(data.data.list,function(y,n){
                         var chanping='<div class="public_goods">'+
'		<a href="7.0.0goods_detail.html?id='+n.id+'">'+
'			<dl>'+
'				<dt>'+
'					<img onerror="errorImg(this)" src="'+n.coverUrl+'" />'+
'					<span>金币可抵'+n.goldRate+'%</span>'+
'				</dt>'+
'				<dd>'+
'					<h5>'+n.goodsTitle+'</h5>'+
'					<h6>&yen;'+n.tradePrice+'</h6>'+ //'- &yen;'+n.packPrice+
'				</dd>'+
'			</dl>'+
'		</a>'+
'	</div>';					  	
                    $("#chanping").append(chanping);
					  });
					 }
			},
			error: function() {
				alert("error");
			}
		});
}
}

function jinbizhongxin(){
		
	             	$.ajax({
        url:urlcore+"/api/goods/selectGoodsListByCondition?current="+currentPage+"&goldRate=3",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//alert(JSON.stringify(data.data.list));
					  $.each(data.data.list,function(y,n){
                         var chanping='<div class="public_goods">'+
'		<a href="7.0.0goods_detail.html?id='+n.id+'">'+
'			<dl>'+
'				<dt>'+
'					<img onerror="errorImg(this)" src="'+n.coverUrl+'" />'+
'					<span>金币可抵'+n.goldRate+'%</span>'+
'				</dt>'+
'				<dd>'+
'					<h5>'+n.goodsTitle+'</h5>'+
'					<h6>&yen;'+n.tradePrice+'</h6>'+ 
'				</dd>'+
'			</dl>'+
'		</a>'+
'	</div>';					  	
                    $("#chanping").append(chanping);
					  	
					  });
					 }
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});
		

}


//商圈
 function shangquan(){
    	 $.ajax({
             url: urlcore + "/api/tradeArea/selectList",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
				//	alert(JSON.stringify(data.data));
				var suns=0;
				var shangquan="";
					  $.each(data.data,function(y,n){
					  	suns++;
					  	if(suns==1){
				 shangquan+='<li  onclick="selsetshangquan2()">全部商圈</li> ';
                
					  	}
 shangquan+='<li  onclick="selsetshangquan('+n.id+',\''+n.areaName+'\')">'+n.areaName+'</li> ';
                    	
					  });
					    $("#shangquan").append(shangquan);					  
				} else if(data.code == 'OVERTIME') {
					var thisUrl = window.location.href;
					alert(thisUrl);
					if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
						top.window.location.href = "1.0.0denglu.html";
					}
				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}
			},
			error: function() {
				alert("error");
			}
		});	
    }
 
 
 function selsetshangquan(id,name){
 
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html(name);
	shangquanid=id;
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
  $("#chanping").html("");
selectRemai();
 	
 	
 }
 
 

 function selsetshangquan2(){
	//alert("..."+name);
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html("全部商圈");
	shangquanid="";
	
	//$("#pfsq span").removeClass('up');
	$('#shangquan').hide();
currentPage=1;
  $("#chanping").html("");
selectRemai();
 }
 

function shaixuanshousuo(){
	var dianpusstype=$("#dianpuleixing").val();
	var remaigoodsstype=$("#remaigoodss").val();
	var shifoubaohuanstype=$("#shifoubaohuans").val();
	var jingbidikoustype=$("#jingbidikous").val();
    var zuishaozhitype=$("#zuishaozhi").val();
    var zuidazhitype=$("#zuidazhi").val();  	
    var qipijianshutype=$("#qipijianshu").val();
    dianpuleixing=dianpusstype;
	remaigoodss=remaigoodsstype;
	shifoubaohuans=shifoubaohuanstype;
	jingbidikous=jingbidikoustype;
    zuishaozhi=zuishaozhitype;
    zuidazhi=zuidazhitype;
/*    if(zuishaozhi<=zuidazhi){
    	alert("价格区间错误");
    	$("#zuidazhi").val("");
    	$("#zuishaozhi").val("");
    	return;
    }*/
    qujianshu=zuishaozhi+"-"+zuidazhi;
   currentPage=1;
	  $("#chanping").html("");
    qipijianshu=qipijianshutype;
    selectRemai();
}
